package com.eduadmin.controller;

import com.alibaba.excel.EasyExcel;
import com.eduadmin.entity.BaseDataTable;
import com.eduadmin.entity.Exam;
import com.eduadmin.listener.BaseDataTableDataUploadListener;
import com.eduadmin.listener.ExamDataUploadListener;
import com.eduadmin.service.IBaseDataTableService;
import com.eduadmin.service.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
public class BaseDataTableController {
    //构造函数自动装配
    private final IBaseDataTableService baseDataTableService;
    @Autowired
    public BaseDataTableController(IBaseDataTableService baseDataTableService){
        this.baseDataTableService= baseDataTableService;
    }
    //导入年级数据
    @RequestMapping(value = "addBaseDataTables")
    @ResponseBody
    public String addExams(MultipartFile baseDataTableFile) throws IOException {
        EasyExcel.read(baseDataTableFile.getInputStream(), BaseDataTable.class, new BaseDataTableDataUploadListener(baseDataTableService)).sheet().doRead();
        return "上传成功";
    }

}
